<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">制令单扫描发料</block>
			</cu-custom>
			<!-- 查询条件 -->
			<view class="fixed" :style="[{animationDelay: 0.1 + 's'}]">
				<view class="cu-form-group">
					<text>需求数量：{{needNums}}</text>
					<text>已发料数量：{{hasScanNums}}</text>
				</view>
				<view class="cu-form-group" v-if="replaceMaterial.length > 0">
					<text>替代料数量：{{replaceMaterial.length}}</text>
					<view class="btn1" @click="openModal">查看</view>
				</view>
				<form>
					<view class="cu-form-group last">
						<image class="icon" src="../../static/saomiao.png" mode=""></image>
						<input auto-focus placeholder="请扫描" name="input" v-model="myFormData.oddNumber" @confirm="inputQuery"></input>
					</view>
				</form>
			</view>
			<view class="list" :style="[{marginTop:replaceMaterial.length > 0 ? '320rpx' : CustomBar + 70 + 'px'}]">
				<view class="card animation-slide-bottom" v-for="(item,index) in list" :key="index" 
				 :style="[{animationDelay: (index + 1)*0.1 + 's'}]">
					<view class="top">
						<view class="left">物料编号：<text>{{item.productCode}}</text></view>
						<view class="right">{{item.inwareNum}}</view>
					</view>
					<view class="line">
						
					</view>
					<view class="bottom">
						<view class="box">
							<view class="lable">
								创建时间:
							</view>
							<view class="content">
								{{item.createTime}}
							</view>
						</view>
						<view class="box">
							<view class="lable">
								名称:
							</view>
							<view class="content">
								{{item.productName}}
							</view>
						</view>
						<view class="box" v-if="item.query3">
							<view class="lable">
								备注:
							</view>
							<view class="content">
								{{item.query3}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<!-- 抬头凭证 输入弹窗 -->
			<template v-if="modalName=='Modal'">
				<view class="cu-modal" :class="modalName=='Modal'?'show':''">
					<view class="cu-dialog">
						<view class="cu-bar bg-white justify-end">
							<view class="content">替代料列表</view>
							<view class="action">
								<text class="cuIcon-close text-red" @click="close"></text>
							</view>
						</view>
						<view class="padding-xl">
							<form>
								<view class="material-item" v-for="item in replaceMaterial">
									<view class="cu-form-group">
										<view class="titls">替代料号：</view>
										<view>{{item.replaceCode}}</view>
									</view>
									<view class="cu-form-group" style="word-break: break-all;">
										<view class="titls" style="min-width: 180rpx;">替代料规格：</view>
										<view>{{item.replaceGague}}</view>
									</view>
									<view class="cu-form-group">
										<view class="titls">替代料名称：</view>
										<view>{{item.replaceName}}</view>
									</view>
								</view>
							</form>
						</view>
					</view>
				</view>
			</template>
			</scroll-view>
	</view>
</template>

<script>
	export default {
		name:'SsuingOfInstructionSheetDetailSaoMiao',
		data() {
			return {
				id:'',
				myFormData: {
					oddNumber: ''
				},
				list:[],
				hasScanNums: 0,
				Issued: 0,
				commandbillId: null,
				replaceMaterial:[],
				modalName: '',
			}
		},
		onLoad(e) {
			this.id = uni.getStorageSync('SsuingOfInstructionSheetDetailId');
			this.needNums = uni.getStorageSync('SsuingOfInstructionRealNum')
			this.getHasScanNums(uni.getStorageSync('SsuingOfInstructionSheetCommandId'))
			this.getMesStorageWholesaleList()
			this.queryMainCode()
			console.log(this.id)
		},
		methods: {
			openModal(){
				this.modalName = 'Modal'
			},
			// 关闭弹窗
			close() {
				this.modalName = '';
			},
			queryMainCode(){//查询是否有替代料
				this.$http.get('chiefdata/mesChiefdataReplacematerial/queryMainCode', {
						params: {
							machineSort:uni.getStorageSync('mechanismCode'),
							mainCode:uni.getStorageSync('materielCode'),
						}
					}).then(res => {
						if (res.data.success) {
							this.replaceMaterial = res.data.result
						} else {
							this.modal.show({ type:'error', content:res.data.message })
						}
					})
			},
			// 获取已扫描数量
			getHasScanNums(id) {
				this.$http.get('produce/mesCommandbillPitem/queryById', {
					params: {id}
				}).then(res => {
					console.log("res1::", res)
					if (res.data.success) {
						this.hasScanNums = res.data.result.deliveryNum
						this.commandbillId = res.data.result.commandbillId
					} else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			// 列表查询
			getMesStorageWholesaleList(){
				uni.showLoading({
					mask:true,
					title:'加载中.....'
				})
				let data = {
					pageNo: 1,
					pageSize: 10000,
					baseRownum:this.id
				}
				this.$http.get('storage/mesStorageWholesale/list', {
					params: data
				}).then(res => {
					uni.hideLoading()
					console.log("res1::", res)
					if (res.data.success) {
						this.list = res.data.result.records;
					} else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			// 扫码查询
			inputQuery(){
				uni.showLoading({
					mask:true,
					title:'查询中.....'
				})
				let data = {
					id : this.myFormData.oddNumber
				}
				this.$http.get('storage/mesStorageWholesale/queryById', {
					params: data
				}).then(res => {
					uni.hideLoading()
					 this.myFormData.oddNumber = ''
					console.log("res2::", res)
					if (res.data.success) {
						this.getMesStorageWholesaleAdd(res.data.result)
					} else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			},
			// 添加
			getMesStorageWholesaleAdd(item){
				uni.showLoading({
					mask:true,
					title:'添加中.....'
				})
				let data = item
				data.baseDockettype = '扫描发料';
				data.baseCode = uni.getStorageSync('SsuingOfInstructionSheetCommandId');
				data.productCode = item.productCode;
				data.query5 = item.id;
				data.id = '';
				data.baseRownum = this.id
				data.createBy =""
				data.createTime =""
				data.query4 = this.commandbillId
				console.log(data)
				// this.$http.post('storage/mesStorageWholesale/add',data
				this.$http.post('storage/mesStorageWholesale/scanSendMateriel',data
				).then(res => {
					console.log("res3::", res)
					uni.hideLoading()
					this.getHasScanNums(uni.getStorageSync('SsuingOfInstructionSheetCommandId'))
					this.getMesStorageWholesaleList()
					if (res.data.success) {
						// this.$tip.success(res.data.message)
            this.modal.show({ type:'success', content:res.data.message })
					} else {
						// this.$tip.error(res.data.message)
            this.modal.show({ type:'error', content:res.data.message })
					}
				})
			}
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f1f1f1;
	
		.fixed {
			position: fixed;
			z-index: 1;
			width: 100%;
			background-color: white;
			height: 100rpx;
			border-bottom: 1rpx solid #eee;
	
			.last {
				border-bottom: 1rpx solid #eee;
				position: relative;
	
				.icon {
					width: 30rpx;
					height: 29rpx;
					position: absolute;
					top: 36rpx;
					left: 60rpx;
				}
	
				input {
					width: 686rpx;
					height: 68rpx;
					background: #FFFFFF;
					border: 1px solid #D5D8DF;
					border-radius: 34px;
					padding-left: 79rpx;
				}
			}
		}
	
		.list {
			// margin-top: 120rpx;
	
			.card {
				margin: 30rpx;
				box-shadow: 0px 0px 5rpx 2rpx rgba(0, 0, 0, 0.1);
				border-radius: 10rpx;
				background-color: white;
	
				.top {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-weight: bold;
					padding: 20rpx 30rpx;
	
					.left {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #485A75;
						line-height: 50rpx;
					}
	
					.right {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #191919;
						line-height: 50rpx;
					}
				}
	
				.line {
					width: 750rpx;
					height: 10rpx;
					background: #F3F5F9;
				}
	
				.bottom {
					padding: 20rpx 30rpx;
	
					.box {
						display: flex;
						justify-content: space-between;
						padding: 20rpx 0;
						align-items: center;
	
						.lable {
							color: #485A75;
							font-size: 28rpx;
						}
	
						.content {
							width: 70%;
							text-align: right;
							color: #191919;
							font-weight: bold;
              word-break: break-all;
						}
	
						.shrink {
							height: 40rpx;
							overflow: hidden;
							white-space: nowrap;
							/*不换行*/
							text-overflow: ellipsis;
							/*超出部分文字以...显示*/
							font-weight: 400;
						}
	
						.unfold {
							text-align: left;
							font-weight: 400;
						}
					}
				}
	
				
			}
		}
	}
	.btns {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 20rpx;
		font-size: 25rpx;
		padding: 20rpx 30rpx;
		
		view {
			width: 180rpx;
			height: 64rpx;
			line-height: 50rpx;
			color: white;
			border-radius: 30rpx;
			padding: 10rpx 20rpx;
			text-align: center;
		}
		
		.btn1 {
			background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
		}
		
		.btn2 {
			background-image: radial-gradient(circle, #716BA9, #362D85, #57509A);
		}
		
		.btn3 {
			background-image: radial-gradient(circle, #354D9E, #354D9E, #697BB7);
		}
	}
	.btn1 {
		width: 180rpx;
		height: 64rpx;
		line-height: 50rpx;
		color: white;
		border-radius: 30rpx;
		padding: 10rpx 20rpx;
		text-align: center;
		background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
	}
	.material-item {
		background-color: #ffffff;
		padding: 1upx 30upx;
		min-height: 100upx;
		margin-bottom: 20rpx;
	}
</style>
